package com.cw.lang.redis.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metric;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisGeoCommands;

import com.cw.lang.redis.service.RedisForGeoService;

import lombok.Getter;
import lombok.Setter;

/**
 * redisTemplate.opsForGeo()操作地理位置
 *
 * @author chenw
 * @version $$Id: RedisForGeoServiceImpl.java, v 0.1 2018/11/19 3:29 PM chenw Exp $$
 */
@Getter
@Setter
public class RedisForGeoServiceImpl<K extends Serializable, V extends Serializable> extends AbstractRedisService<K, V>
    implements RedisForGeoService<K, V> {

    @Override
    public Long add(K key, Point point, V member) {
        return getRedisTemplate(key).opsForGeo()
            .add(key, point, member);
    }

    @Override
    public Long add(K key, RedisGeoCommands.GeoLocation<V> location) {
        return getRedisTemplate(key).opsForGeo()
            .add(key, location);
    }

    @Override
    public Long add(K key, Map<V, Point> memberCoordinateMap) {
        return getRedisTemplate(key).opsForGeo()
            .add(key, memberCoordinateMap);
    }

    @Override
    public Long add(K key, Iterable<RedisGeoCommands.GeoLocation<V>> geoLocations) {
        return getRedisTemplate(key).opsForGeo()
            .add(key, geoLocations);
    }

    @Override
    public Distance distance(K key, V member1, V member2) {
        return getRedisTemplate(key).opsForGeo()
            .distance(key, member1, member2);
    }

    @Override
    public Distance distance(K key, V member1, V member2, Metric metric) {
        return getRedisTemplate(key).opsForGeo()
            .distance(key, member1, member2, metric);
    }

    @Override
    public List<String> hash(K key, V... members) {
        return getRedisTemplate(key).opsForGeo()
            .hash(key, members);
    }

    @Override
    public List<Point> position(K key, V... members) {
        return getRedisTemplate(key).opsForGeo()
            .position(key, members);
    }

    @Override
    public GeoResults<RedisGeoCommands.GeoLocation<V>> radius(K key, Circle within) {
        return getRedisTemplate(key).opsForGeo()
            .radius(key, within);
    }

    @Override
    public GeoResults<RedisGeoCommands.GeoLocation<V>> radius(K key, Circle within,
        RedisGeoCommands.GeoRadiusCommandArgs args) {
        return getRedisTemplate(key).opsForGeo()
            .radius(key, within, args);
    }

    @Override
    public GeoResults<RedisGeoCommands.GeoLocation<V>> radius(K key, V member, double radius) {
        return getRedisTemplate(key).opsForGeo()
            .radius(key, member, radius);
    }

    @Override
    public GeoResults<RedisGeoCommands.GeoLocation<V>> radius(K key, V member, Distance distance) {
        return getRedisTemplate(key).opsForGeo()
            .radius(key, member, distance);
    }

    @Override
    public GeoResults<RedisGeoCommands.GeoLocation<V>> radius(K key, V member, Distance distance,
        RedisGeoCommands.GeoRadiusCommandArgs args) {
        return getRedisTemplate(key).opsForGeo()
            .radius(key, member, distance, args);
    }

    @Override
    public Long remove(K key, V... members) {
        return getRedisTemplate(key).opsForGeo()
            .remove(key, members);
    }

}
